<template>
  <div class="select-wrapper">
    <select
      :value="modelValue"
      class="theme-select toolbar-select"
      @change="handleChange"
      :title="title"
    >
      <option v-for="option in options" :key="option.value" :value="option.value">
        {{ option.label }}
      </option>
    </select>
    <div class="select-arrow"></div>
  </div>
</template>

<script lang="ts">
export default {
  name: 'ThemeSelect',
  props: {
    modelValue: {
      type: String,
      required: true,
    },
    title: {
      type: String,
      default: '选择主题',
    },
    options: {
      type: Array as () => Array<{ value: string; label: string }>,
      default: () => [
        { value: 'oneDark', label: 'One Dark' },
        { value: 'dark', label: 'Dark' },
        { value: 'light', label: 'Light' },
        { value: 'github', label: 'GitHub' },
        { value: 'monokai', label: 'Monokai' },
      ],
    },
  },
  emits: ['update:modelValue'],
  methods: {
    handleChange(event: Event) {
      const target = event.target as HTMLSelectElement
      this.$emit('update:modelValue', target.value)
    },
  },
}
</script>

<style scoped>
/* 选择框容器 */
.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

/* 自定义下拉箭头 */
.select-arrow {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid #64748b;
  pointer-events: none;
}

.toolbar-select {
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  height: 28px;
  box-sizing: border-box;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
  padding-right: 24px;
  background-color: white;
  border: 1px solid #e2e8f0;
  color: #334155;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.toolbar-select:hover {
  border-color: #cbd5e1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.toolbar-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.theme-select {
  width: 105px;
}

/* 暗色主题工具栏下的样式调整 */
.dark-toolbar .toolbar-select {
  background-color: #1e293b;
  border-color: #475569;
  color: #f1f5f9;
}

.dark-toolbar .toolbar-select:hover {
  border-color: #64748b;
}

.dark-toolbar .select-arrow {
  border-top-color: #94a3b8;
}

/* 响应式样式 */
@media (max-width: 768px) {
  .theme-select {
    width: auto;
  }
}
</style>
